package com.hongji.lms5xxcommunicator.controller;

import com.hongji.lms5xxcommunicator.entity.GridBootstrapParam;
import com.hongji.lms5xxcommunicator.entity.GridSnapshotDto;
import com.hongji.lms5xxcommunicator.service.GridBootstrapService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/grid")
@RequiredArgsConstructor
@Slf4j
public class GridBootstrapController {

    private final GridBootstrapService bootstrapService;

    @GetMapping("/bootstrap")
    public ResponseEntity<GridSnapshotDto> bootstrap(@Valid GridBootstrapParam p) {
        // 放宽：若未给 specId 且未给六要素，则由服务端使用系统默认 spec
        log.info("Bootstrap 请求: {}, pageSize={}, cursor={}", p, p.getPageSize(), p.getCursor());
        GridSnapshotDto dto = bootstrapService.buildSnapshot(p);
        return ResponseEntity.ok(dto);
    }
}
